package com.manolovn.sample;

import com.manolovn.trianglify.TrianglifyView;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.Attr;
import ohos.agp.components.AttrSet;
import ohos.agp.render.ColorMatrix;
import ohos.agp.utils.Rect;
import ohos.app.Context;

import org.junit.Before;
import org.junit.Test;

import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * ExampleOhosTest entity
 */
public class ExampleOhosTest {
    private Context mContext;
    private AttrSet attrSet;

    /**
     * setUp
     */
    @Before
    public void setUp() {
        mContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

        attrSet = new AttrSet() {
            @Override
            public Optional<String> getStyle() {
                return Optional.empty();
            }

            @Override
            public int getLength() {
                return 0;
            }

            @Override
            public Optional<Attr> getAttr(int i) {
                return Optional.empty();
            }

            @Override
            public Optional<Attr> getAttr(String s) {
                return Optional.empty();
            }
        };
    }

    /**
     * testBundleName will return true if bundle name matches otherwise false
     */
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.manolovn.sample", actualBundleName);
    }

    @Test
    public void testTrianglifyDrawable() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        assertNotNull(trianglifyView.getDrawable());
    }

    @Test
    public void testTrianglifyBottom() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.setBottom(30);
        assertEquals(30, trianglifyView.getBottom());
    }

    @Test
    public void testTrianglifyLeft() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.setLeft(45);
        assertEquals(45, trianglifyView.getLeft());
    }

    @Test
    public void testTrianglifyTop() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.setTop(35);
        assertEquals(35, trianglifyView.getTop());
    }

    @Test
    public void testTrianglifyRight() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.setRight(25);
        assertEquals(25, trianglifyView.getRight());
    }

    @Test
    public void testTrianglifyDrawableBounds() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.getDrawable().setBounds(new Rect(20,10,20,10));
        assertNotNull(trianglifyView.getDrawable().getBounds());
    }

    @Test
    public void testTrianglifyDrawableColorMatrix() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.getDrawable().setColorMatrix(new ColorMatrix());
        assertNotNull(trianglifyView.getDrawable().getColorMatrix());
    }

    @Test
    public void testTrianglifyDrawableCornerRadius() {
        TrianglifyView trianglifyView = new TrianglifyView(mContext, attrSet);
        trianglifyView.getDrawable().setCornerRadius(15);
        assertEquals(15, (int)trianglifyView.getDrawable().getCornerRadius());
    }
}